<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Login extends CI_Controller {
  
    public function __construct()
    {
        parent::__construct();
       
    }
    public function index(){
    
    	$this->load->view('admin/login_form');
    }
	public function verify(){
		$this->form_validation->set_rules('username', 'name', 'required');
		$this->form_validation->set_rules('password', 'password', 'required');
		if ($this->form_validation->run()==FALSE){
			$this->load->view('admin/login_form');
		}else{
			$query = $this->employee_model->validate();
			if ($query == TRUE){
				;
				$data = array(
					'is_logged_in' => TRUE,
					'name' => $query[0]['name'],
					'SUPER' => FALSE,
					'id' => $query[0]['id'],
					'type' => $query[0]['type']
				);
				$this->session->set_userdata($data);
				redirect('admin'); 
				
			}else{
				echo 'you were not found in the DB';
			}
		}
	}
	public function logout(){
		$this->session->set_userdata('is_logged_in', 'false');
		$this->session->sess_destroy();
		redirect('welcome');
	}


}

